package com.example.dukesbank.web.template;

import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.util.ArrayList;
import java.util.HashMap;

public class ScreenTag extends SimpleTagSupport {
	private ArrayList<Parameter> parameters = null;
	private String screenId;

	public ScreenTag() {
		super();
	}

	public ArrayList<Parameter> getParameters() {
		return parameters;
	}

	public void setScreenId(String screenId) {
		this.screenId = screenId;
	}

	@Override
	public void doTag() {
		parameters = new ArrayList<Parameter>();

		HashMap<String, ArrayList<Parameter>> screens = ((DefinitionTag) getParent())
				.getScreens();

		if (screens != null) {
			try {
				if (!screens.containsKey(screenId)) {
					screens.put(screenId, parameters);
				}

				getJspBody().invoke(null);
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		} else {
			Debug.println("ScreenTag: Unable to get screens object.");
		}
	}
}
